package com.netease.image.video;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;

public class ActivityCropImage extends MonitoredActivity
{
  boolean a;
  boolean b;
  ao c;
  Runnable d = new h(this);
  private Bitmap.CompressFormat e = Bitmap.CompressFormat.JPEG;
  private Uri f = null;
  private boolean g = false;
  private boolean h = true;
  private final Handler i = new Handler();
  private CropImageView j;
  private ContentResolver k;
  private Bitmap l;

  public static void a(Activity paramActivity, int paramInt, Bitmap paramBitmap)
  {
    Intent localIntent = new Intent(paramActivity, ActivityCropImage.class);
    localIntent.setAction("set_wallpaper");
    Bundle localBundle = new Bundle();
    localBundle.putParcelable("data", paramBitmap);
    localBundle.putBoolean("wallpaper", true);
    localIntent.putExtras(localBundle);
    localIntent.addFlags(67108864);
    paramActivity.startActivityForResult(localIntent, paramInt);
  }

  public static void a(Activity paramActivity, int paramInt, Bitmap paramBitmap, Uri paramUri, String paramString)
  {
    Intent localIntent = new Intent(paramActivity, ActivityCropImage.class);
    localIntent.setAction("save");
    Bundle localBundle = new Bundle();
    localBundle.putParcelable("data", paramBitmap);
    localBundle.putParcelable("output", paramUri);
    localBundle.putString("format", paramString);
    localIntent.putExtras(localBundle);
    paramActivity.startActivityForResult(localIntent, paramInt);
  }

  private void a(Bitmap paramBitmap)
  {
    OutputStream localOutputStream;
    int m;
    if (this.f != null)
    {
      localOutputStream = null;
      m = 1;
    }
    while (true)
    {
      try
      {
        localOutputStream = this.k.openOutputStream(this.f);
        if (localOutputStream == null)
          continue;
        paramBitmap.compress(this.e, 75, localOutputStream);
        al.a(localOutputStream);
        Bundle localBundle2 = new Bundle();
        if (m != 0)
        {
          setResult(-1, new Intent(this.f.toString()).putExtras(localBundle2));
          this.i.post(new k(this, paramBitmap));
          finish();
          return;
        }
      }
      catch (IOException localIOException2)
      {
        localIOException2.printStackTrace();
        al.a(localOutputStream);
        m = 0;
        continue;
      }
      finally
      {
        al.a(localOutputStream);
      }
      setResult(0);
      continue;
      if (this.g)
      {
        try
        {
          setWallpaper(paramBitmap);
          setResult(-1);
        }
        catch (IOException localIOException1)
        {
          localIOException1.printStackTrace();
          setResult(0);
        }
        continue;
      }
      Bundle localBundle1 = new Bundle();
      localBundle1.putParcelable("data", paramBitmap);
      setResult(-1, new Intent().putExtras(localBundle1));
    }
  }

  private void b()
  {
    if (isFinishing());
    while (true)
    {
      return;
      this.j.a(this.l, true, true);
      al.a(this, null, getString(2131362174), new i(this), this.i);
    }
  }

  public static void b(Activity paramActivity, int paramInt, Bitmap paramBitmap)
  {
    Intent localIntent = new Intent(paramActivity, ActivityCropImage.class);
    localIntent.setAction("crop");
    Bundle localBundle = new Bundle();
    localBundle.putParcelable("data", paramBitmap);
    localBundle.putBoolean("wallpaper", false);
    localIntent.putExtras(localBundle);
    paramActivity.startActivityForResult(localIntent, paramInt);
  }

  private void c()
  {
    if (this.c == null)
      return;
    Bitmap localBitmap;
    if (!this.b)
    {
      this.b = true;
      Rect localRect1 = this.c.b();
      int m = localRect1.width();
      int n = localRect1.height();
      localBitmap = Bitmap.createBitmap(m, n, Bitmap.Config.RGB_565);
      Canvas localCanvas = new Canvas(localBitmap);
      Rect localRect2 = new Rect(0, 0, m, n);
      localCanvas.drawBitmap(this.l, localRect1, localRect2, null);
      this.j.a();
      this.l.recycle();
      this.j.a(localBitmap, true, true);
      this.j.a(true, true);
      this.j.a.clear();
      if (!this.g)
        break label168;
    }
    label168: for (String str = getString(2131362175); ; str = getString(2131362176))
    {
      al.a(this, null, str, new l(this, localBitmap), this.i);
      break;
      break;
    }
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.k = getContentResolver();
    requestWindowFeature(1);
    setContentView(2130903051);
    this.j = ((CropImageView)findViewById(2131558436));
    Intent localIntent = getIntent();
    Bundle localBundle = localIntent.getExtras();
    if (localBundle == null)
      finish();
    while (true)
    {
      return;
      this.l = ((Bitmap)localBundle.getParcelable("data"));
      if ("save".equals(localIntent.getAction()))
      {
        this.f = ((Uri)localBundle.getParcelable("output"));
        String str = localBundle.getString("format");
        if (str != null)
          this.e = Bitmap.CompressFormat.valueOf(str);
      }
      while (true)
      {
        if (this.l != null)
          break label184;
        finish();
        break;
        if ("set_wallpaper".equals(localIntent.getAction()))
        {
          this.g = localBundle.getBoolean("wallpaper");
          continue;
        }
        if (!"crop".equals(localIntent.getAction()))
          continue;
        this.g = false;
      }
      label184: getWindow().addFlags(1024);
      findViewById(2131558438).setOnClickListener(new n(this));
      findViewById(2131558437).setOnClickListener(new j(this));
      b();
    }
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    return super.onKeyDown(paramInt, paramKeyEvent);
  }
}

/* Location:           D:\android\hack\dex2jar-0.0.9.8\classes_dex2jar.jar
 * Qualified Name:     com.netease.image.video.ActivityCropImage
 * JD-Core Version:    0.6.0
 */